/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package taglibs;

import daos.CategoryDAO;
import java.util.ArrayList;
import java.util.Iterator;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import models.Category;
import util.Common;

/**
 *
 * @author trietto
 */
public class Categories extends TagSupport {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    /*
     * (non-Javadoc)
     * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
     */
    public int doStartTag() {
        try {
            JspWriter writer = pageContext.getOut();
            writer.println("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
            writer.println("<tr>");
            writer.println("<td align='center'><b>CATEGORIES</b><br></td>");
            writer.println("</tr>");

            ArrayList<Category> lstCategories = CategoryDAO.singleton().selectAll();
            for (Category category : lstCategories) {
                writer.println("<tr>");
                writer.println("<td><a href='BookList.jsp?categoryid="
                        + category.getCategoryId() + "'>" + category.getName() + "</a></td>");
                writer.println("</tr>");
            }
            writer.println("</table>");
        } catch (Exception e) {
        }
        return SKIP_BODY;
    }
}
